package com.nuanshui.heatedloan.baseservice.service;

import com.nuanshui.heatedloan.baseservice.dal.mapper.ClientVersionMapper;
import com.nuanshui.heatedloan.baseservice.facade.ClientVersionService;
import com.nuanshui.heatedloan.baseservice.model.ClientVersion;
import com.nuanshui.heatedloan.constant.DubboCacheRegion;
import com.nuanshui.heatedloan.constant.ServiceConstant;
import com.nuanshui.heatedloan.constant.TransactionManagerType;
import com.nuanshui.heatedloan.dubbo.extension.cache.manager.DubboCacheManager;
import com.nuanshui.heatedloan.pageable.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(ServiceConstant.CLIENTVERSIONSERVICE)
@Transactional(readOnly=true,  value = TransactionManagerType.BASE_SERVICE_TRANSACTION_MANAGER)
public class ClientVersionServiceImpl implements ClientVersionService{

	@Autowired
	private ClientVersionMapper clientVersionMapper;

	@Autowired
	private DubboCacheManager dubboCacheManager;

	@Override
	public Pager<ClientVersion> list(Pager<ClientVersion> pager, ClientVersion cv) {
		List<ClientVersion> list=clientVersionMapper.list(pager,cv);
		pager.setData(list);
		return pager;
	}

	@Override
	@Transactional(readOnly=false,  value = TransactionManagerType.BASE_SERVICE_TRANSACTION_MANAGER)
	public void save(ClientVersion cv) {
		clientVersionMapper.save(cv);
		dubboCacheManager.evictCache(DubboCacheRegion.CHACHE_CONSTANT_CLIENT_VERSION,cv.getType());
	}

	@Override
	@Transactional(readOnly=false,  value = TransactionManagerType.BASE_SERVICE_TRANSACTION_MANAGER)
	public void delete(String id) {
		clientVersionMapper.delete(id);
		dubboCacheManager.evictCache(DubboCacheRegion.CHACHE_CONSTANT_CLIENT_VERSION);
	}

	@Override
	@Transactional(readOnly=false,  value = TransactionManagerType.BASE_SERVICE_TRANSACTION_MANAGER)
	public void update(ClientVersion cv) {
		clientVersionMapper.update(cv);
		dubboCacheManager.evictCache(DubboCacheRegion.CHACHE_CONSTANT_CLIENT_VERSION,cv.getType());
	}

	@Override
	public ClientVersion getNewClientVersion(String type) {
		return clientVersionMapper.getNewClientVersion(type);
	}



}
